package com.antis.olsl.data.introduction;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.alibaba.android.arouter.launcher.ARouter;
import com.antis.olsl.base.BaseActivity;
import com.antis.olsl.base.response.BaseResp;
import com.antis.olsl.data.adapter.PurchaseGoodsFiledListAdapter;
import com.antis.olsl.data.databinding.ActivityIntroductionGoodsDetailsBinding;
import com.antis.olsl.library.bean.GoodsFiledInfo;
import com.antis.olsl.library.bean.GoodsInfo;
import com.antis.olsl.library.common.ConstantsPool;
import com.antis.olsl.library.utils.StringUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * @ProjectName: ATS_OLSL
 * @Package: com.antis.olsl.activity.purchaseQuery
 * @ClassName: PurchaseSlipGoodsDetailsActivity
 * @Description: 采购单商品详情
 * @Author: 羊琪
 * @CreateDate: 2020/3/30 19:48
 * @UpdateDate: 2020/3/30 19:48
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class IntroductionSlipGoodsDetailsActivity extends BaseActivity<ActivityIntroductionGoodsDetailsBinding> {
    boolean fromSalesroom = false;
    String productId;
    String purchaseNumber;
    private ArrayList<GoodsFiledInfo> filedInfos = new ArrayList<>();
    private PurchaseGoodsFiledListAdapter adapter;

    @Override
    protected ActivityIntroductionGoodsDetailsBinding getViewBinding() {
        return ActivityIntroductionGoodsDetailsBinding.inflate(getLayoutInflater(), baseBinding.getRoot(), true);
    }

    @Override
    protected void initViews() {
        ARouter.getInstance().inject(this);
        viewBinding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new PurchaseGoodsFiledListAdapter(filedInfos);
        viewBinding.recyclerView.setAdapter(adapter);
    }

    @Override
    protected void initData() throws IllegalAccessException {
        if (getIntent().getExtras() != null) {
            fromSalesroom = getIntent().getExtras().getBoolean(ConstantsPool.FROM_SALESROOM_OR_WAREHOUSE);
            purchaseNumber = getIntent().getExtras().getString(ConstantsPool.PURCHASE_SLIP_ID);
            productId = getIntent().getExtras().getString(ConstantsPool.GOODS_ID);
        }
        getDetails();
    }

    /**
     * 获取商品详情
     */
    private void getDetails() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("introductionNumber", purchaseNumber);
        map.put("productId", productId);
        // okHttpClient.postJsonObjectParams(fromSalesroom ? UrlServerConnections.GET_GOODS_DETAILS_FOR_INTRODUCTION : UrlServerConnections.GET_GOODS_DETAILS_FOR_INTRODUCTION, map, GetIntroductionGoodsRes.class);
    }

    public void successResponse(BaseResp baseRes) {
//        if (baseRes instanceof GetIntroductionGoodsRes) {
//            GetIntroductionGoodsRes goodsDetailsRes = (GetIntroductionGoodsRes) baseRes;
//            setData(goodsDetailsRes.getContent());
//        }
    }

    private void setData(GoodsInfo goodsInfo) {
        if (goodsInfo == null) {
            return;
        }
        filedInfos.add(new GoodsFiledInfo("商品名称", goodsInfo.getProductName()));
        filedInfos.add(new GoodsFiledInfo("商品编码", goodsInfo.getProductCode()));
        filedInfos.add(new GoodsFiledInfo("商品条码", goodsInfo.getBarCode()));
        filedInfos.add(new GoodsFiledInfo("商品规格", goodsInfo.getSpecification()));
        filedInfos.add(new GoodsFiledInfo("供应商名称", goodsInfo.getSupplierName()));
        filedInfos.add(new GoodsFiledInfo("品牌名称", goodsInfo.getBrandName()));
        filedInfos.add(new GoodsFiledInfo("商品单位", goodsInfo.getUnit()));
        filedInfos.add(new GoodsFiledInfo("装箱规格", goodsInfo.getPackingSpecification()));
        filedInfos.add(new GoodsFiledInfo("商品分类", goodsInfo.getGoodsCategory()));
        filedInfos.add(new GoodsFiledInfo("产地", goodsInfo.getOriginArea()));
        filedInfos.add(new GoodsFiledInfo("进价", StringUtils.getCommaFormat(BigDecimal.valueOf(goodsInfo.getPurchasePrice())) + "元"));
        filedInfos.add(new GoodsFiledInfo("进价折扣", StringUtils.getCommaFormat(BigDecimal.valueOf(goodsInfo.getPurchaseDiscount() * 100)) + "%"));
        filedInfos.add(new GoodsFiledInfo("税率", StringUtils.getCommaFormat(BigDecimal.valueOf(goodsInfo.getTaxRate() * 100)) + "%"));
        filedInfos.add(new GoodsFiledInfo("含税进价", StringUtils.getCommaFormat(BigDecimal.valueOf(goodsInfo.getTaxPurchasePrice())) + "元"));
        filedInfos.add(new GoodsFiledInfo("不含税进价", StringUtils.getCommaFormat(BigDecimal.valueOf(goodsInfo.getExcludingTaxPurchasePrice())) + "元"));
        filedInfos.add(new GoodsFiledInfo("零售价金额", StringUtils.getCommaFormat(BigDecimal.valueOf(goodsInfo.getRetailPrice())) + "元"));
        filedInfos.add(new GoodsFiledInfo("统一零售价金额", StringUtils.getCommaFormat(BigDecimal.valueOf(goodsInfo.getUnifyRetailPrice())) + "元"));
        adapter.setList(filedInfos);
    }
}
